package cn.wu.reggie.controller;

import cn.wu.reggie.common.R;
import cn.wu.reggie.dto.SetmealDto;
import cn.wu.reggie.query.SetmealQuery;
import cn.wu.reggie.service.ISetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("setmeal")
public class SetmealController {


    @Autowired
    private ISetmealService setmealService;

    @PostMapping
    public R setmeal(@RequestBody SetmealDto setmealDto, HttpSession session){
        // 1 获取seesion中的用户对象  登录对象 保存创建人和修改人
        Long userId = (Long) session.getAttribute("employee");
        setmealDto.setUpdateUser(userId);
        setmealDto.setCreateUser(userId);
        // 2 调用
        return setmealService.saveWithSetmeal(setmealDto);
    }

    @GetMapping("page")
    public R page(SetmealQuery qo){
        return setmealService.findByPage(qo);
    }

    @DeleteMapping
    public R delete(@RequestParam("ids") List<Long> ids){

        System.out.println(ids);
        setmealService.deleteByIds(ids);
        System.out.println("==============");
        return R.success(null);
    }

}
